export function setToken(token, tokenTime) {
  localStorage.setItem('token', token)
  // 记录token过期时间（小时转换为毫秒）
  const expireTime = Date.now() + tokenTime * 60 * 60 * 1000
  localStorage.setItem('tokenExpireTime', expireTime)
}

export function getToken() {
  const token = localStorage.getItem('token')
  const expireTime = localStorage.getItem('tokenExpireTime')
  
  if (token && expireTime) {
    // 判断是否过期
    if (Date.now() < Number(expireTime)) {
      return token
    } else {
      // token过期，清除存储
      removeToken()
      return null
    }
  }
  return null
}

export function removeToken() {
  localStorage.removeItem('token')
  localStorage.removeItem('tokenExpireTime')
  localStorage.removeItem('userId')
  localStorage.removeItem('loginTime')
} 